<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>开始使用layui</title>
    <link rel="stylesheet" href="/static/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/login.css">
</head>

<body style="background-color: white;">
    <div class="layui-container container">
        <div class="layui-row div_row1">
            <div class="layui-col-md8 div_row2">
                <img src="/static/images/login.jpg" class="img_size">
            </div>

            <div class="layui-col-md4">
                <div class="layui-input-block">
                    <label class="layui-form-label controller">控制系统</label>
                </div>

                <form class="layui-form form1">
                    {% csrf_token %}
                    <div class="layui-form-item">
                        <label class="layui-form-label"><i
                                class="layui-icon layui-icon-username icon_user"></i>&nbsp;&nbsp;账号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" value="1296100904@qq.com" id="username"
                                lay-verify="required" placeholder="请输入用户代码" autocomplete="off"
                                class="layui-input input_username">
                        </div>
                    </div>
                    <br />
                    <div class="layui-form-item">
                        <label class="layui-form-label"><i
                                class="layui-icon layui-icon-password icon_pass"></i>&nbsp;&nbsp;密码：</label>

                        <div class="layui-input-block">
                            <input type="password" name="password" value="galaxys9" id="password" lay-verify="required"
                                placeholder="请输入密码" autocomplete="off" class="layui-input input_pass">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" type="submit" lay-submit
                                lay-filter="loginFilter">&nbsp;&nbsp;&nbsp;登&nbsp;&nbsp;录&nbsp;&nbsp;&nbsp;</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                    <p style="text-align: center;color: red;" class="errormsg;">{{ errormsg }}</p>
                </form>
                <div class="layui-input-block foot_block">
                    <label class="layui-form-label tips">推荐使用MicrosoftEdge/Chrome/Firefox浏览器使用，最佳分辨率：1920x1080</label>
                </div>
                <div class="layui-input-block foot_block">
                    <label class="layui-form-label copyright">Copyright ©2018-©2021 zhang v2.0 All Rights
                        Reserved</label>
                </div>
            </div>

        </div>
    </div>
    <script src="/static/lib/layui/layui.js"></script>
    <script src="/static/js/jquery-1.11.2.min.js"></script>
    <script>
        //一般直接写在一个js文件中
        layui.use(['layer', 'form', 'jquery'], function () {
            var layer = layui.layer;
            var form = layui.form;
            var $ = layui.jquery;
            $(document).ready(function () {
                $("#username").focus();
            });
            form.on('submit(loginFilter)', function (data) {
                $.ajax({
                    url: "{% url 'system:login' %}",
                    type: "POST",
                    data: data.field,
                    success: function (res) {
                        if (res.code == 200) {
                            layer.msg(res.msg, { icon: 1, time: 2000, shift: 6 }, function () {
                                location.href = '/index/'
                            });//一个笑脸
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 2000, shift: 6 });//一个哭脸
                        }
                    }
                });
                return false;
            });
        });
        $(function () {
            //判断一下当前是不是做顶层，如果不是，则做一下顶层页面重定向
            if (self != top) {
                    top.location.href = location.href;
            }
        });
    </script>
</body>

</html>